package com.connector.server.jmx;

import redis.clients.jedis.Jedis;
import com.connector.server.redis.RedisSubscriber;
import com.connector.base.config.InstantConfig;
import com.connector.server.redis.RedisPoolConfig;
import com.connector.server.util.PushMsgUtil;
import com.alibaba.fastjson.JSON;
import java.util.concurrent.Executors;
import java.util.concurrent.Executor;
import com.connector.server.redis.AbstractRedisPubSubListener;

public class RedisCustomerService extends AbstractRedisPubSubListener
{
    private Executor singleExecutorService;
    
    public RedisCustomerService() {
        this.singleExecutorService = Executors.newFixedThreadPool(1);
    }
    
    @Override
    public void doMessage(final String message) {
        final JmxMessageBean jmxMessageBean = (JmxMessageBean)JSON.parseObject(message, (Class)JmxMessageBean.class);
        PushMsgUtil.pushMsg(jmxMessageBean);
    }
    
    public void start() {
        final RedisCustomerService handler = new RedisCustomerService();
        final Jedis jedis = RedisPoolConfig.getJedis();
        this.singleExecutorService.execute(new RedisSubscriber(InstantConfig.server.jmx.topic, jedis, handler));
    }
}
